
var path = "toCN.json";
var file = new XMLHttpRequest();
var json
file.open("get", path);
file.send(null);
file.onload = function () {
    if (file.status == 200) {
        json = JSON.parse(file.response);
    }
}

function main() {

    var EN_words = []
    for (var EN_word in json) {
        CN_word = json[EN_word]
        EN_words.push(EN_word)
    }
    // replace
    span = document.getElementsByTagName("span");
    // special
    input = document.getElementsByTagName("input");
    for (var i in input) {
        v = input[i]["placeholder"];
        if (EN_words.includes(v)) {
            console.log(v);
            CN_word = json[v];
            input[i]["placeholder"] = CN_word;
        }
    }

    div = document.getElementsByTagName("div");
    p = document.getElementsByTagName("p");
    button = document.getElementsByTagName("button");
    h1 = document.getElementsByTagName("h1");
    h2 = document.getElementsByTagName("h2");
    label = document.getElementsByTagName("label");
    legend = document.getElementsByTagName("legend");
    all = [div, p, button, h1, h2, label, legend];
    for (var part in all) {
        part = all[part];
        for (var i in part) {
            v = part[i].innerHTML;
            if (EN_words.includes(v)) {
                console.log(v);
                CN_word = json[v];
                v = v.replace(v, CN_word);
                part[i].innerHTML = v;
            }
        }
    }
}


document.body.addEventListener("mousemove", main);
document.body.addEventListener("mouseover", main);
document.body.addEventListener("mouseout", main);
document.body.addEventListener("click", main);